//Map

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

//Map有两个实现方法:HashMap和TreeMap
public class TestDemo2 {

    public static void main(String[] args) {
        Map<Integer,String> map1 = new TreeMap<>();
        map1.put(10,"aa");
        map1.put(2,"bb");
        System.out.println(map1);//TreeMap会自动排序
    }

    public static void main2(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("2","bb");
        map.put("1","aa");
        System.out.println(map);//这里打印顺序是不一定的

        Set<Map.Entry<String,String>> entries = map.entrySet();
        for (Map.Entry<String,String> entry: entries) {
            System.out.println("key"+entry.getKey() + "value:" + entry.getValue());
        }
    }

    public static void main1(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("1","aa");
        map.put("2","bb");

        System.out.println(map.get("1"));
        System.out.println(map.getOrDefault("3", "zjk"));
        System.out.println(map.containsKey("1"));
    }
}
